package com.zzgc.modules.controller;

import com.auth0.jwt.exceptions.TokenExpiredException;
import com.zzgc.common.dao.SchoolTableDao;
import com.zzgc.common.utils.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Author:
 * @CreateTime: 2022-11-16  14:05
 * @Description:
 * @Version: 1.0
 */
@RestController
@RequestMapping("test")
@Api(tags = "项目测试接口")
public class TestController extends BaseController{
    @Resource
    SchoolTableDao schoolTableDao;

    @RequestMapping("addTable")
    @ApiOperation(value = "创建数据表", notes = "创建数据表")
    public String addTable(String name){
        int i = schoolTableDao.addSchoolTable(name);
        System.out.println("i = " + i);
        List<String> list = schoolTableDao.queryTableName(name);
        System.out.println("list = " + list);
        return list.get(0);
    }

    @RequestMapping("login")
    @ApiOperation(value = "测试登陆", notes = "测试登陆的API")
    public String login(){
        String tableName = getTableName("410103");
        return "成功!" +tableName;
    }

    @PostMapping("test")
    @ApiOperation("错误捕获")
    public void test(){
        throw new TokenExpiredException("开始减肥");
    }

    @GetMapping("speed")
    @ApiOperation("Websocket进度测试")
    public void speed(String name) throws InterruptedException {
        for (int i = 0; i <= 1000; ) {
            float f = i++/1000f*100;
            Thread.sleep(10);
            WsController.broadcast(name, String.format("%.2f", f));
        }
    }

    public static void main(String[] args) {
//        String s = "郑州市金水区教育局_2022学年_第1次筛查";
//        for (String s1 : s.split("_")) {
//            System.out.println("s1 = " + s1);
//        }
//        System.out.println(s.substring(0, s.indexOf("_") + 1));
        long l = 0;
        tess(l);
    }

    public static void tess(Long l){
        System.out.println("l = " + l);
    }

}
